<!doctype HTML>
<script src="../../resources/ahem.js"></script>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script>
function line_boundary_test(id, dir, input, output, direction) {
  selection_test(
      `<div contenteditable style="direction:${dir}">${input}</div>`,
      selection => selection.modify('move', direction, 'lineBoundary'),
      `<div contenteditable style="direction:${dir}">${output}</div>`,
      `${id}-${dir.toUpperCase()} ${direction}`);
}

const kSample01 = [
  '|abc \u05D0\u05D1\u05D2 xyz \u05D3\u05D4\u05D5 def',
  'abc \u05D0\u05D1\u05D2 xyz \u05D3\u05D4\u05D5 def|',
];
line_boundary_test(1, 'ltr', kSample01[0], kSample01[1], 'forward');
line_boundary_test(1, 'ltr', kSample01[1], kSample01[0], 'backward');
line_boundary_test(1, 'ltr', kSample01[0], kSample01[1], 'right');
line_boundary_test(1, 'ltr', kSample01[1], kSample01[0], 'left');
line_boundary_test(1, 'rtl', kSample01[0], kSample01[1], 'forward');
line_boundary_test(1, 'rtl', kSample01[1], kSample01[0], 'backward');
line_boundary_test(1, 'rtl', kSample01[0], kSample01[0], 'right');
line_boundary_test(1, 'rtl', kSample01[0], kSample01[1], 'left');

const kSample02 = [
  '|\u05D0\u05D1\u05D2 xyz \u05D3\u05D4\u05D5 def \u05D6\u05D7\u05D8',
  '\u05D0\u05D1\u05D2 xyz \u05D3\u05D4\u05D5 def \u05D6\u05D7\u05D8|',
];
line_boundary_test(2, 'ltr', kSample02[0], kSample02[1], 'forward');
line_boundary_test(2, 'ltr', kSample02[1], kSample02[0], 'backward');
line_boundary_test(2, 'ltr', kSample02[0], kSample02[1], 'right');
line_boundary_test(2, 'ltr', kSample02[1], kSample02[0], 'left');
line_boundary_test(2, 'rtl', kSample02[0], kSample02[1], 'forward');
line_boundary_test(2, 'rtl', kSample02[1], kSample02[0], 'backward');
line_boundary_test(2, 'rtl', kSample02[0], kSample02[0], 'right');
line_boundary_test(2, 'rtl', kSample02[0], kSample02[1], 'left');

const kSample03 = [
  '|\u05D0\u05D1\u05D2 \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2',
  '\u05D0\u05D1\u05D2 \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2|',
];
line_boundary_test(3, 'ltr', kSample03[0], kSample03[1], 'forward');
line_boundary_test(3, 'ltr', kSample03[1], kSample03[0], 'backward');
line_boundary_test(3, 'ltr', kSample03[0], kSample03[1], 'right');
line_boundary_test(3, 'ltr', kSample03[1], kSample03[0], 'left');
line_boundary_test(3, 'rtl', kSample03[0], kSample03[1], 'forward');
line_boundary_test(3, 'rtl', kSample03[1], kSample03[0], 'backward');
line_boundary_test(3, 'rtl', kSample03[0], kSample03[0], 'right');
line_boundary_test(3, 'rtl', kSample03[0], kSample03[1], 'left');

const kSample04 = [
  '|abc efd dabeb',
  'abc efd dabeb|',
];
line_boundary_test(4, 'ltr', kSample04[0], kSample04[1], 'forward');
line_boundary_test(4, 'ltr', kSample04[1], kSample04[0], 'backward');
line_boundary_test(4, 'ltr', kSample04[0], kSample04[1], 'right');
line_boundary_test(4, 'ltr', kSample04[1], kSample04[0], 'left');
line_boundary_test(4, 'rtl', kSample04[0], kSample04[1], 'forward');
line_boundary_test(4, 'rtl', kSample04[1], kSample04[0], 'backward');
line_boundary_test(4, 'rtl', kSample04[0], kSample04[0], 'right');
line_boundary_test(4, 'rtl', kSample04[0], kSample04[1], 'left');

const kSample05 = [
  '|abc <span style="direction:rtl">def ghi jkl</span> mno',
  'abc <span style="direction:rtl">def ghi jkl</span> mno|',
];
line_boundary_test(5, 'ltr', kSample05[0], kSample05[1], 'forward');
line_boundary_test(5, 'ltr', kSample05[1], kSample05[0], 'backward');
line_boundary_test(5, 'ltr', kSample05[0], kSample05[1], 'right');
line_boundary_test(5, 'ltr', kSample05[1], kSample05[0], 'left');
line_boundary_test(5, 'rtl', kSample05[0], kSample05[1], 'forward');
line_boundary_test(5, 'rtl', kSample05[1], kSample05[0], 'backward');
line_boundary_test(5, 'rtl', kSample05[0], kSample05[0], 'right');
line_boundary_test(5, 'rtl', kSample05[0], kSample05[1], 'left');

const kSample06 = [
  '|abc <span style="direction:rtl">def ghi<div> just a test</div> jkl</span> mno',
  'abc <span style="direction:rtl">def ghi|<div> just a test</div> jkl</span> mno',
];
line_boundary_test(6, 'ltr', kSample06[0], kSample06[1], 'forward');
line_boundary_test(6, 'ltr', kSample06[1], kSample06[0], 'backward');
line_boundary_test(6, 'ltr', kSample06[0], kSample06[1], 'right');
line_boundary_test(6, 'ltr', kSample06[1], kSample06[0], 'left');
line_boundary_test(6, 'rtl', kSample06[0], kSample06[1], 'forward');
line_boundary_test(6, 'rtl', kSample06[1], kSample06[0], 'backward');
line_boundary_test(6, 'rtl', kSample06[0], kSample06[0], 'right');
line_boundary_test(6, 'rtl', kSample06[0], kSample06[1], 'left');

const kSample07 = [
  '|abc <span dir="rtl">def ghi jkl</span> mno',
  'abc <span dir="rtl">def ghi jkl</span> mno|',
];
line_boundary_test(7, 'ltr', kSample07[0], kSample07[1], 'forward');
line_boundary_test(7, 'ltr', kSample07[1], kSample07[0], 'backward');
line_boundary_test(7, 'ltr', kSample07[0], kSample07[1], 'right');
line_boundary_test(7, 'ltr', kSample07[1], kSample07[0], 'left');
line_boundary_test(7, 'rtl', kSample07[0], kSample07[1], 'forward');
line_boundary_test(7, 'rtl', kSample07[1], kSample07[0], 'backward');
line_boundary_test(7, 'rtl', kSample07[0], kSample07[0], 'right');
line_boundary_test(7, 'rtl', kSample07[0], kSample07[1], 'left');

const kSample08 = [
  '|abc <div dir="rtl">def ghi jkl</div> mno',
  'abc| <div dir="rtl">def ghi jkl</div> mno',
];
line_boundary_test(8, 'ltr', kSample08[0], kSample08[1], 'forward');
line_boundary_test(8, 'ltr', kSample08[1], kSample08[0], 'backward');
line_boundary_test(8, 'ltr', kSample08[0], kSample08[1], 'right');
line_boundary_test(8, 'ltr', kSample08[1], kSample08[0], 'left');
line_boundary_test(8, 'rtl', kSample08[0], kSample08[1], 'forward');
line_boundary_test(8, 'rtl', kSample08[1], kSample08[0], 'backward');
line_boundary_test(8, 'rtl', kSample08[0], kSample08[0], 'right');
line_boundary_test(8, 'rtl', kSample08[0], kSample08[1], 'left');

const kSample09 = [
  '|abc <span style="direction:ltr">def ghi jkl</span> mno',
  'abc <span style="direction:ltr">def ghi jkl</span> mno|',
];
line_boundary_test(9, 'ltr', kSample09[0], kSample09[1], 'forward');
line_boundary_test(9, 'ltr', kSample09[1], kSample09[0], 'backward');
line_boundary_test(9, 'ltr', kSample09[0], kSample09[1], 'right');
line_boundary_test(9, 'ltr', kSample09[1], kSample09[0], 'left');
line_boundary_test(9, 'rtl', kSample09[0], kSample09[1], 'forward');
line_boundary_test(9, 'rtl', kSample09[1], kSample09[0], 'backward');
line_boundary_test(9, 'rtl', kSample09[0], kSample09[0], 'right');
line_boundary_test(9, 'rtl', kSample09[0], kSample09[1], 'left');

const kSample10 = [
  '|abc <span style="direction:ltr">def ghi<div> just a test</div> jkl</span> mno',
  'abc <span style="direction:ltr">def ghi|<div> just a test</div> jkl</span> mno',
];
line_boundary_test(10, 'ltr', kSample10[0], kSample10[1], 'forward');
line_boundary_test(10, 'ltr', kSample10[1], kSample10[0], 'backward');
line_boundary_test(10, 'ltr', kSample10[0], kSample10[1], 'right');
line_boundary_test(10, 'ltr', kSample10[1], kSample10[0], 'left');
line_boundary_test(10, 'rtl', kSample10[0], kSample10[1], 'forward');
line_boundary_test(10, 'rtl', kSample10[1], kSample10[0], 'backward');
line_boundary_test(10, 'rtl', kSample10[0], kSample10[0], 'right');
line_boundary_test(10, 'rtl', kSample10[0], kSample10[1], 'left');

const kSample11 = [
  '|abc <span dir="ltr">def ghi jkl</span> mno',
  'abc <span dir="ltr">def ghi jkl</span> mno|',
];
line_boundary_test(11, 'ltr', kSample11[0], kSample11[1], 'forward');
line_boundary_test(11, 'ltr', kSample11[1], kSample11[0], 'backward');
line_boundary_test(11, 'ltr', kSample11[0], kSample11[1], 'right');
line_boundary_test(11, 'ltr', kSample11[1], kSample11[0], 'left');
line_boundary_test(11, 'rtl', kSample11[0], kSample11[1], 'forward');
line_boundary_test(11, 'rtl', kSample11[1], kSample11[0], 'backward');
line_boundary_test(11, 'rtl', kSample11[0], kSample11[0], 'right');
line_boundary_test(11, 'rtl', kSample11[0], kSample11[1], 'left');

const kSample12 = [
  '|abc <div dir="ltr">def ghi jkl</div> mno',
  'abc| <div dir="ltr">def ghi jkl</div> mno',
];
line_boundary_test(12, 'ltr', kSample12[0], kSample12[1], 'forward');
line_boundary_test(12, 'ltr', kSample12[1], kSample12[0], 'backward');
line_boundary_test(12, 'ltr', kSample12[0], kSample12[1], 'right');
line_boundary_test(12, 'ltr', kSample12[1], kSample12[0], 'left');
line_boundary_test(12, 'rtl', kSample12[0], kSample12[1], 'forward');
line_boundary_test(12, 'rtl', kSample12[1], kSample12[0], 'backward');
line_boundary_test(12, 'rtl', kSample12[0], kSample12[0], 'right');
line_boundary_test(12, 'rtl', kSample12[0], kSample12[1], 'left');

const kSample13 = [
  '|abc <span>def \u05E8\u05E7</span> \u05D1\u05D5\u05D3\u05E7',
  'abc <span>def \u05E8\u05E7</span> \u05D1\u05D5\u05D3\u05E7|',
];
line_boundary_test(13, 'ltr', kSample13[0], kSample13[1], 'forward');
line_boundary_test(13, 'ltr', kSample13[1], kSample13[0], 'backward');
line_boundary_test(13, 'ltr', kSample13[0], kSample13[1], 'right');
line_boundary_test(13, 'ltr', kSample13[1], kSample13[0], 'left');
line_boundary_test(13, 'rtl', kSample13[0], kSample13[1], 'forward');
line_boundary_test(13, 'rtl', kSample13[1], kSample13[0], 'backward');
line_boundary_test(13, 'rtl', kSample13[0], kSample13[0], 'right');
line_boundary_test(13, 'rtl', kSample13[0], kSample13[1], 'left');

const kSample14 = [
  '|abc <span>def ghi</span> jkl',
  'abc <span>def ghi</span> jkl|',
];
line_boundary_test(14, 'ltr', kSample14[0], kSample14[1], 'forward');
line_boundary_test(14, 'ltr', kSample14[1], kSample14[0], 'backward');
line_boundary_test(14, 'ltr', kSample14[0], kSample14[1], 'right');
line_boundary_test(14, 'ltr', kSample14[1], kSample14[0], 'left');
line_boundary_test(14, 'rtl', kSample14[0], kSample14[1], 'forward');
line_boundary_test(14, 'rtl', kSample14[1], kSample14[0], 'backward');
line_boundary_test(14, 'rtl', kSample14[0], kSample14[0], 'right');
line_boundary_test(14, 'rtl', kSample14[0], kSample14[1], 'left');

const kSample15 = [
  '|abc def \u05D0\u05D1\u05D2.',
  'abc def \u05D0\u05D1\u05D2.|',
];
line_boundary_test(15, 'ltr', kSample15[0], kSample15[1], 'forward');
line_boundary_test(15, 'ltr', kSample15[1], kSample15[0], 'backward');
line_boundary_test(15, 'ltr', kSample15[0], kSample15[1], 'right');
line_boundary_test(15, 'ltr', kSample15[1], kSample15[0], 'left');
line_boundary_test(15, 'rtl', kSample15[0], kSample15[1], 'forward');
line_boundary_test(15, 'rtl', kSample15[1], kSample15[0], 'backward');
line_boundary_test(15, 'rtl', kSample15[0], kSample15[0], 'right');
line_boundary_test(15, 'rtl', kSample15[0], kSample15[1], 'left');

const kSample16 = [
  '|\u202Bxyz \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2.\u202C',
  '\u202Bxyz| \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2.\u202C',
  '\u202Bxyz \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2.\u202C|',
];
line_boundary_test(16, 'ltr', kSample16[0], kSample16[1], 'forward');
line_boundary_test(16, 'ltr', kSample16[1], kSample16[0], 'backward');
line_boundary_test(16, 'ltr', kSample16[0], kSample16[1], 'right');
line_boundary_test(16, 'ltr', kSample16[1], kSample16[0], 'left');
line_boundary_test(16, 'rtl', kSample16[0], kSample16[2], 'forward');
line_boundary_test(16, 'rtl', kSample16[1], kSample16[0], 'backward');
line_boundary_test(16, 'rtl', kSample16[0], kSample16[0], 'right');
line_boundary_test(16, 'rtl', kSample16[0], kSample16[2], 'left');

const kSample17 = [
  '|abc "\u202Bxyz \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."',
  'abc "\u202Bxyz \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C."|',
];
line_boundary_test(17, 'ltr', kSample17[0], kSample17[1], 'forward');
line_boundary_test(17, 'ltr', kSample17[1], kSample17[0], 'backward');
line_boundary_test(17, 'ltr', kSample17[0], kSample17[1], 'right');
line_boundary_test(17, 'ltr', kSample17[1], kSample17[0], 'left');
line_boundary_test(17, 'rtl', kSample17[0], kSample17[1], 'forward');
line_boundary_test(17, 'rtl', kSample17[1], kSample17[0], 'backward');
line_boundary_test(17, 'rtl', kSample17[0], kSample17[0], 'right');
line_boundary_test(17, 'rtl', kSample17[0], kSample17[1], 'left');

const kSample18 = [
  '|\u05D6\u05D7\u05D8 \'\u202Axyz abc "\u202Bxyz \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C"\u202C\'?',
  '\u05D6\u05D7\u05D8 \'\u202Axyz abc "\u202Bxyz \u05D3\u05D4\u05D5 \u05D0\u05D1\u05D2\u202C"\u202C\'?|',
];
line_boundary_test(18, 'ltr', kSample18[0], kSample18[1], 'forward');
line_boundary_test(18, 'ltr', kSample18[1], kSample18[0], 'backward');
line_boundary_test(18, 'ltr', kSample18[0], kSample18[1], 'right');
line_boundary_test(18, 'ltr', kSample18[1], kSample18[0], 'left');
line_boundary_test(18, 'rtl', kSample18[0], kSample18[1], 'forward');
line_boundary_test(18, 'rtl', kSample18[1], kSample18[0], 'backward');
line_boundary_test(18, 'rtl', kSample18[0], kSample18[0], 'right');
line_boundary_test(18, 'rtl', kSample18[0], kSample18[1], 'left');

const kSample19 = [
  '|\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>def \u05D6\u05D7\u05D8 ghi',
  '\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5|<br>def \u05D6\u05D7\u05D8 ghi',
];
line_boundary_test(19, 'ltr', kSample19[0], kSample19[1], 'forward');
line_boundary_test(19, 'ltr', kSample19[1], kSample19[0], 'backward');
line_boundary_test(19, 'ltr', kSample19[0], kSample19[1], 'right');
line_boundary_test(19, 'ltr', kSample19[1], kSample19[0], 'left');
line_boundary_test(19, 'rtl', kSample19[0], kSample19[1], 'forward');
line_boundary_test(19, 'rtl', kSample19[1], kSample19[0], 'backward');
line_boundary_test(19, 'rtl', kSample19[0], kSample19[0], 'right');
line_boundary_test(19, 'rtl', kSample19[0], kSample19[1], 'left');

const kSample20 = [
  '<div style="font-family:Ahem; line-break:before-white-space; width:8ch">|abcdefg hijklm opqrstu v wxyz</div>',
  '<div style="font-family:Ahem; line-break:before-white-space; width:8ch">abcdefg |hijklm opqrstu v wxyz</div>',
];
line_boundary_test(20, 'ltr', kSample20[0], kSample20[1], 'forward');
// TODO(yosin): output should be kSample20[0].
line_boundary_test(20, 'ltr', kSample20[1], kSample20[1], 'backward');
line_boundary_test(20, 'ltr', kSample20[0], kSample20[1], 'right');
line_boundary_test(20, 'ltr', kSample20[1], kSample20[1], 'left');
line_boundary_test(20, 'rtl', kSample20[0], kSample20[1], 'forward');
// TODO(yosin): output should be kSample20[0].
line_boundary_test(20, 'rtl', kSample20[1], kSample20[1], 'backward');
line_boundary_test(20, 'rtl', kSample20[0], kSample20[0], 'right');
line_boundary_test(20, 'rtl', kSample20[0], kSample20[1], 'left');

const kSample21 = [
  '<div style="font-family:Ahem; line-break:after-white-space; width:8ch">|abcdefg hijklm opqrstu v wxyz</div>',
  '<div style="font-family:Ahem; line-break:after-white-space; width:8ch">abcdefg |hijklm opqrstu v wxyz</div>',
];
line_boundary_test(21, 'ltr', kSample21[0], kSample21[1], 'forward');
// TODO(yosin): output should be kSample21[0].
line_boundary_test(21, 'ltr', kSample21[1], kSample21[1], 'backward');
line_boundary_test(21, 'ltr', kSample21[0], kSample21[1], 'right');
line_boundary_test(21, 'ltr', kSample21[1], kSample21[1], 'left');
line_boundary_test(21, 'rtl', kSample21[0], kSample21[1], 'forward');
// TODO(yosin): output should be kSample21[0].
line_boundary_test(21, 'rtl', kSample21[1], kSample21[1], 'backward');
line_boundary_test(21, 'rtl', kSample21[0], kSample21[0], 'right');
line_boundary_test(21, 'rtl', kSample21[0], kSample21[1], 'left');
</script>
